/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entity.AboutUs;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Young Ran
 */
public class AboutUsDAO {
    
    private Connection cn;
    private PreparedStatement pstm;
    private CallableStatement cs;
    
    public AboutUsDAO() {
        cn = DB_Util.getConnection();
    }
    
    private ArrayList<AboutUs> getAboutUsData(ResultSet rs) throws SQLException {
        ArrayList<AboutUs> list = new ArrayList<AboutUs>();
        while (rs.next()) {
            AboutUs e = new AboutUs();
            e.setId(rs.getInt("AboutUsId"));
            e.setDetail(rs.getString("AboutUsDetail"));
            list.add(e);
        }
        return list;
    }
    
    //DISPLAY ABOUTUS:
    public ArrayList<AboutUs> getAllAboutUs() throws SQLException {
        cs = cn.prepareCall("{call SP_Display_AboutUs()}");
        ResultSet rs = cs.executeQuery();
        return getAboutUsData(rs);
    }


    //SEARCH ABOUTUS:
    public ArrayList<AboutUs> getAboutUsById(int id) throws SQLException {
        cs = cn.prepareCall("{call SP_Search_AboutUs(?)}");
        cs.setInt(1, id);
        return getAboutUsData(cs.executeQuery());
    }
    
    public void editAboutUs(AboutUs item) throws SQLException
    {
        cs = cn.prepareCall("{call SP_Edit_AboutUs(?,?)}");
        cs.setInt(1, item.getId());
        cs.setString(2, item.getDetail());
        cs.execute();
    
    }
    
}
